home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
tcplusx.zip
/
TESTEVT.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-27
|
4KB
|
156 lines
//
// testevt.cpp - test module for class Event and EventManager
// Author - Robin W. McKean
// Last Update - February 23,1991
// Copyright (C) 1991 All rights reserved
//
//
// Interface dependencies ---------------------------------------------------
// None
// End interface dependencies -----------------------------------------------
// Implementation dependencies ----------------------------------------------
#ifndef _EVENTMGR_H
#include <eventmgr.h>
#endif
#ifndef _CURSOR_H
#include <cursor.h>
#endif
#ifndef _KEYBOARD_H
#include <keyboard.h>
#endif
#ifndef _MOUSE_H
#include <mouse.h>
#endif
#ifndef _IOSTREAM_H
#include <iostream.h>
#endif
#ifndef _DOS_H
#include <dos.h>
#define _DOS_H
#endif
// End implementation dependencies ------------------------------------------
EventManager *theEventManager;
Mouse *theMouse;
Keyboard *theKeyboard;
Cursor *theCursor;
void errorExit( char *string );
void processEvent( const Event& theEvent );
// Main Module //
#pragma argsused
int main( int argc, char **argv )
{
// Create our event manager from the heap
theEventManager = new EventManager( 50 );
// Create our devices for input from the heap
theMouse = new Mouse;
theKeyboard = new Keyboard;
theCursor = new Cursor;
// Body Comment -------------------------------------------------------------
//
// We add the devices to the event manager. We add the pointers, becuase
// the overloaded operator += takes a Object&.
//
// End ----------------------------------------------------------------------
*theEventManager += *theMouse;
*theEventManager += *theKeyboard;
*theEventManager += *theCursor;
// Turn off the cursor because its in the way
theEventManager->hideDevice( cursorClass );
Event theEvent;
do {
theEventManager->getEvent( theEvent );
if( theEvent.typeCode != 27 )
{
theEventManager->hideDevice( mouseClass );
processEvent( theEvent );
theEventManager->showDevice( mouseClass );
}
} while( theEvent.typeCode != 27 );
// Turn the cursor back on
theEventManager->showDevice( cursorClass );
// Body Comment -------------------------------------------------------------
//
// We do not have to destroy our devices, because, when the event manager
// is destroyed, the devices added to him will automatically be done so.
//
// End ----------------------------------------------------------------------
delete theEventManager;
return( 0 );
}
void errorExit( char *string )
{
if( string ) cout << "\ntestevt: " << string << "\n\n";
}
void processEvent( const Event& theEvent )
{
cout << "\nEvent Type: ";
switch( theEvent.type )
{
case E_KEY:
cout << "Keyboard ==> " << hex;
cout << "Shift State: " << "0x" << theEvent.shiftState << "\t";
cout << "Key Code: 0x" << theEvent.typeCode << "\n\n" << dec;
break;
case E_MOUSE:
cout << "Mouse ==> ";
switch( theEvent.typeCode )
{
case M_LEFT_SELECT:
cout << "Left button is pressed!" << "\n\n";
break;
case M_MIDDLE_SELECT:
cout << "Middle button is pressed!" << "\n\n";
break;
case M_RIGHT_SELECT:
cout << "Right button is pressed!" << "\n\n";
break;
case M_MIDDLE_RELEASE:
cout << "Middle button is released!" << "\n\n";
break;
case M_LEFT_RELEASE:
cout << "Left button is released!" << "\n\n";
break;
case M_RIGHT_RELEASE:
cout << "Right button is released!" << "\n\n";
break;
case M_RCONTINUE_SELECT:
cout << "Right button is still pressed!\n\n";
break;
case M_LCONTINUE_SELECT:
cout << "Left button is still pressed!\n\n";
break;
case M_MCONTINUE_SELECT:
cout << "Middle button is still pressed!\n\n";
break;
}
}
}